package botcraft.gui;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

public class About extends GuiApplication {
	private static final Logger LOGGER = Logger.getLogger(About.class.getName());
	
	private final JEditorPane about;
	
	public static void main(final String[] arguments) {
		try {
			GuiApplication.invoke(new About());
		} catch (final InterruptedException e) {
		} catch (final InvocationTargetException e) {
			LOGGER.log(Level.SEVERE, "Error invoking about", e);
			JOptionPane.showMessageDialog(null, "Error invoking about", e.getMessage(), JOptionPane.ERROR_MESSAGE);
		} catch (final IOException e) {
			LOGGER.log(Level.SEVERE, "Error invoking about", e);
			JOptionPane.showMessageDialog(null, "Error invoking about", e.getMessage(), JOptionPane.ERROR_MESSAGE);
		}
	}

	public About() throws IOException {
		super();
		about = new JEditorPane(About.class.getResource(getResourceBundle().getString("_about")));
	}
	
	@Override
	public void run() {
		final JFrame frame = new JFrame(getResourceBundle().getString("about"));
		final Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
		final Dimension size = new Dimension(Double.valueOf(bounds.getWidth()).intValue(), Double.valueOf(bounds.getHeight()).intValue());
		frame.setMaximumSize(size);
		frame.setPreferredSize(size);
		about.setEditable(false);
		frame.add(new JScrollPane(about, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
		frame.pack();
		frame.setVisible(true);
		frame.requestFocusInWindow();
	}
}
